<!-- http://ogp.me/ -->
<!-- https://developers.facebook.com/docs/sharing/webmasters -->
<!-- https://developers.google.com/web/fundamentals/discovery/social-discovery/ -->
<!-- https://stackoverflow.com/a/29831974 -->
<!-- https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html -->
{{- $Deliver := .Deliver -}}
{{- $description := .description -}}
{{- $keywords := .keywords -}}
<!-- Title -->
{{- partial "components/title.html" $Deliver -}}
{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}}
<!-- Date -->
{{- partial "components/date.html" $Deliver -}}
{{- $pubDate := $Deliver.Scratch.Get "pubDate" -}}
{{- $modDate := $Deliver.Scratch.Get "modDate" -}}
<!-- Author -->
{{- partial "components/author.html" $Deliver -}}
{{- $author := $Deliver.Scratch.Get "author" -}}
<!-- Images -->
{{- partial "components/images.html" $Deliver -}}
{{- $images := $Deliver.Scratch.Get "images" -}}
<!-- languageCode -->
{{- if $Deliver.Site.IsMultiLingual -}}
    {{- $languageCode := readFile "config.toml" | findRE `languageCode = "([^"]+)` | uniq -}}
    {{- with $languageCode -}}
        {{- $Deliver.Scratch.Delete "languageCode" -}}
        {{- range . -}}
            {{- $languageCode := replaceRE `languageCode = "([^"]+)` `$1` . -}}
            {{- $Deliver.Scratch.Add "languageCode" (slice $languageCode) -}}
        {{- end -}}
    {{- end -}}
{{- end -}}
{{- $languageCode := $Deliver.Scratch.Get "languageCode" -}}

<meta property="og:title" content="{{ $rawTitle }}" />
<meta property="og:description" content="{{ $description }}" />
<meta property="og:url" content="{{ $Deliver.Permalink }}" />
<meta property="og:site_name" content="{{ $Deliver.Site.Title }}" />
<meta property="og:locale" content="{{ $Deliver.Site.LanguageCode }}" />
{{- if $Deliver.Site.IsMultiLingual -}}
    {{- range $languageCode -}}
        {{ if ne . $Deliver.Site.LanguageCode }}
            <meta property="og:locale:alternate" content="{{ . }}" />
        {{ end }}
    {{- end -}}
{{- end -}}

{{- with $images -}}
    <meta property="og:image" content="{{ index . 0 }}" />
{{ else -}}
    {{ with $Deliver.Site.Params.siteLogo -}}
        <meta property="og:image" content="{{ . | absURL }}" />
    {{ end -}}
{{- end -}}

{{- if and $Deliver.IsPage (in $Deliver.Site.Params.mainSections $Deliver.Section) -}}
    <meta property="og:type" content="article" />
    {{ printf `<meta property="article:published_time" content="%s" />` $pubDate | safeHTML }}
    {{ printf `<meta property="article:modified_time" content="%s" />` $modDate | safeHTML }}
    {{ if not $Deliver.ExpiryDate.IsZero -}}
        {{ printf `<meta property="article:expiration_time" content="%s" />` ($Deliver.ExpiryDate.Format "2006-01-02T15:04:05-07:00") | safeHTML }}
    {{- end }}
    <meta property="article:section" content="{{ $Deliver.Section }}" />
    <meta property="article:tag" content="{{ $keywords }}" />
{{ else -}}
    <meta property="og:type" content="website" />
{{- end }}